package factory

// Creator 负责根据 id 创建新实例。
type Creator interface {
	RegisterCreator(id string, fn func(...any) (any, error)) error
	UnregisterCreator(id string)
	Create(id string, args ...any) (any, error)
}

// VarStorer 负责存取单例值。
type VarStorer interface {
	RegisterVar(id string, val any) error
	GetVar(id string) any
	RemoveVar(id string)
	RangeVarList(cb func(val any) bool)
	RangeVarKVList(cb func(key string, val any) bool)
}

var (
	DefaultCreator      Creator
	DefaultVarStorer    VarStorer
	DefaultCacheGetFunc = func(k string) (v any, ok bool) {
		panic("DefaultCacheGetFunc Is null")
		return nil, false
	}
)

func init() {
	df := NewFactoryWrapper()
	DefaultCreator = df
	DefaultVarStorer = df
}
